# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=meld
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}3"
pkgver=3.15.2
pkgrel=1
pkgdesc="Visual diff and merge tool (mingw-w64)"
arch=('any')
url="http://meldmerge.org/"
license=("GPL" "LGPL")
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-gtksourceview3"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-python2-gobject")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             #"${MINGW_PACKAGE_PREFIX}-python2-cx_freeze"
             'intltool'
             'itstool')
install=meld-${CARCH}.install
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        '0001-fixes-for-MinGW-w64-symlinks-and-use-sh-to-spawn.patch'
        "0002-build-exe.patch")
sha256sums=('7df34d973dd96163cb1c85bae7d713be610a53f49f2450acb01d501cea24ad16'
            '7c1bdd83b01a11f91019dea7db346f146601bb27c02735557f3278c255efda89'
            '0eafcc76ae1498245f24d1058e2accc34abe328f54e4b9711627dcc03cfa7bbd')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-fixes-for-MinGW-w64-symlinks-and-use-sh-to-spawn.patch"
  #patch -p1 -i "${srcdir}/0002-build-exe.patch"
  sed -i 's/env python/env python2/' bin/meld
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  PYTHON=${MINGW_PREFIX}/bin/python2 DISTUTILS_DEBUG=1 ${MINGW_PREFIX}/bin/python2 setup.py build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py --no-update-icon-cache --no-compile-schemas \
    install --prefix=${MINGW_PREFIX} --root="${pkgdir}"
  PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/bin/meld
}
